package org.apache.servicecomb.samples.practise.houserush.gateway.config;

import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Snake Man
 * @system:
 * @DateTime: 2022/1/9 21:59
 * @Description:
 */
public class LoginUrlConfig {

    //读取
    private DynamicStringProperty needLoginUrls = DynamicPropertyFactory.getInstance()
            .getStringProperty("gateway.needLoginUrls", "");
    private DynamicStringProperty noNeedLoginUrls = DynamicPropertyFactory.getInstance()
            .getStringProperty("gateway.noNeedLoginUrls", "");

    //解析
    private Set<String> needLoginUrlsSet = new HashSet<>
            (Arrays.asList(needLoginUrls.get().split(",")));
    private Set<String> noNeedLoginUrlsSet = new HashSet<>
            (Arrays.asList(noNeedLoginUrls.get().split(",")));


    public LoginUrlConfig() {
        needLoginUrls.addCallback(() -> needLoginUrlsSet = new
                HashSet<>(Arrays.asList(needLoginUrls.get().split(","))));
        noNeedLoginUrls.addCallback(() -> noNeedLoginUrlsSet = new
                HashSet<>(Arrays.asList(noNeedLoginUrls.get().split(","))));
    }

    public Set<String> getNeedLoginUrlsSet() {
        return needLoginUrlsSet;
    }

    public Set<String> getNoNeedLoginUrlsSet() {
        return noNeedLoginUrlsSet;
    }
}

